from string import ascii_lowercase
from itertools import cycle,izip

file = open("cipher1.txt", "r")
line = file.next()
values = [int(x) for x in line.split(",")]

file = open("common-english-words.txt", "r")
line = file.next()
words = line.split(",")

for key in [(ord(x),ord(y),ord(z))
            for x in ascii_lowercase
            for y in ascii_lowercase
            for z in ascii_lowercase]:
    decoded = "".join([chr(x ^ y) for (x,y) in izip(values, cycle(key))])
    nrwords = sum(decoded.count(w) for w in words)
    if nrwords > 50:
        print [chr(k) for k in key], sum(ord(c) for c in decoded)
        print decoded
        break
    
